package our.pack;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

public class MediaViewAudioActivity extends Activity {

	private TextView title, label;
	private ImageView play;
	private String path;
	private MediaPlayer mp;
	
	public void onCreate(Bundle SaveInstanceState){
		super.onCreate(SaveInstanceState);
		setContentView(R.layout.mediaaudio);
		
		//gets the path and the point where it's made
		Intent i = getIntent();
		Bundle b = i.getExtras();
		path = (String) b.get("PATH");
		Log.d("Audio PATH", path);
		
		//UI
		title = (TextView) findViewById(R.id.recordTitel);
		title.setText("Playing Sound");
		label = (TextView) findViewById(R.id.recordingLabel);
		label.setText("Not Playing");
		
		mp = new MediaPlayer();
		
		//when clicked on the "button" play the audio
		play = (ImageView) findViewById(R.id.microphone);
		play.setOnClickListener(new OnClickListener(){
			public void onClick(View v){
				
				try {
					mp.setDataSource(path);
					
					mp.prepare();
					mp.start();
					
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
					
				} catch (IllegalStateException e) {
					e.printStackTrace();
					
				} catch (IOException e) {
					e.printStackTrace();
					
				}
				
				label.setText("Played");
			}
		});
		
		
	}
}
